<?php
declare(strict_types=1);
namespace App\Controller\Web;

use App\Request\WebLoginRequest;
use App\Request\WebSignUpRequest;
use App\Services\CommonService;
use App\Services\UserService;
use Hyperf\Di\Annotation\Inject;

class AuthController extends BaseController
{
    /**
     * @Inject
     * @var CommonService
     */
    protected $commonService;

    /**
     * @Inject
     * @var UserService
     */
    protected $userService;

    public function login(){
        return $this->view('web.login',[]);
    }

    public function doSignUp(WebSignUpRequest $request){
        if(!$this->commonService->checkCapture($request)){
            return $this->apiReponse->error(10040,'验证码不正确');
        }
        if(!$this->commonService->checkSmsCode($request)){
            return $this->apiReponse->error(10040,'短信验证码不正确');
        }
        $return = $this->userService->signUp($request->all());
        if($return['success']){
            return $this->apiReponse->success([]);
        }
        return $this->apiReponse->error(10040,$return['msg']);
    }

    public function doLogin(WebLoginRequest $request){
        $return = $this->userService->webLogin($request->all());
        if($return['success']){
            return $this->apiReponse->success([]);
        }
        return $this->apiReponse->error(10010,$return['msg']);
    }
}